<?php
// +----------------------------------------------------------------------
// | [RhaPHP System] Copyright (c) 2017 http://www.rhaphp.com/
// +----------------------------------------------------------------------
// | [RhaPHP] 并不是自由软件,你可免费使用,未经许可不能去掉RhaPHP相关版权
// +----------------------------------------------------------------------
// | Author: Geeson <qimengkeji@vip.qq.com>
// +----------------------------------------------------------------------


namespace addons\hlapp\model;

use addons\hlapp\controller\FileCache;
use addons\hlapp\dto\PageInfo;
use think\Db;
use think\Model;

class HlappPart extends CommonModel
{

    // 总部部门id
    static $CENTERTYPE = [1,2,3,8,9];

    /**
     * @var array 工程中心、集采中心、运营中心
     */
    static $MAJORCENTERTYPE = [1,2,3];

    //非总部部门id
    static $NOCENTERTYPE = [4,5,6,7];
    //运营中心
    static $OPERATE = 1;
    //工程中心
    static $ENGINEERING = 2;
    //集采中心
    static $COLLECTION = 3;
    //甲方总负责人
    static $AMANAGER = 4;
    //甲方工程负责人
    static $AENGINEER = 5;
    //区域总负责人
    static $MANAGER = 6;
    //区域工程负责人
    static $ENGINEER = 7;

    static $TOPMANAGER = 9;



    public function members(){
        return $this->hasMany('HlappMember','partId','id')->field('id,name,phone,partId');
    }

    public function pmembers(){
        return $this->belongsToMany('HlappMember','hlapp_project_roles_member','m_id','r_id');
    }

    /**
     * 从缓存获取部门信息
     * @return mixed
     * @throws \think\exception\DbException
     */
    public static function getParts(){
        $part_cache_name = "hl_part_info";
        $cache = new FileCache();
        $part_info = $cache->get($part_cache_name);
        if (!$part_info){
            \Log::INFO("更新部门缓存");
            $part_info = HlappPart::all();
            $cache->set($part_cache_name,$part_info);
        }
        return $part_info;
    }

}